<template>
    <div class="money-box" v-loading="loading">
        <el-table
            :data="tableData"
            border
            style="width: 100%">
            <!-- <el-table-column
                fixed
                prop="id"
                label="ID">
            </el-table-column> -->
            <el-table-column width="100" label="提现方式">
                  <template slot-scope="scope">
                      <span>{{ scope.row.type === 1 ? '微信' : scope.row.type === 2 ? '支付宝' : '-' }}</span>
                  </template>
                </el-table-column>
            <el-table-column
                width="100"
                prop="applyMoney"
                label="提现金额">
                <template slot-scope="scope">
                      <span>{{ scope.row.applyMoney}}元</span>
                  </template>
            </el-table-column>
            <el-table-column
                prop="applyCoin"
                label="趣金币">
                <template slot-scope="scope">
                    <div>-{{conversion(scope.row.applyCoin)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="applyTime"
                width="180"
                label="提现时间">
                <template slot-scope="scope">
                     <div>{{initTime(scope.row.applyTime)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="dealTime"
                width="180"
                label="处理时间">
                <template slot-scope="scope">
                     <div>{{initTime(scope.row.dealTime)}}</div>
                </template>
            </el-table-column>
            <!-- <el-table-column
                width="150"
                prop="applyRecord"
                label="提现记录">
            </el-table-column> -->
            
            
            <!-- <el-table-column
                prop="gemNum"
                label="提现趣宝石">
                <template slot-scope="scope">
                    <div>{{conversion(scope.row.gemNum)}}</div>
                </template>
            </el-table-column>
            <el-table-column
                prop="appplyAccount"
                width="180"
                label="提现账号">
            </el-table-column>
            <el-table-column
                prop="applyName"
                label="提现姓名">
            </el-table-column> -->
            <el-table-column
                prop="applyStatus"
                label="提现状态">
                <template slot-scope="scope">
                    <span v-if="scope.row.applyStatus === '2'">数据不同步</span>
                    <span v-else-if="scope.row.applyStatus === '-1'">打款失败</span>
                    <span v-else-if="scope.row.applyStatus === '0'">未处理</span>
                    <span v-else-if="scope.row.applyStatus === '1'">打款中</span>
                    <span v-else-if="scope.row.applyStatus === '2'">需要重试</span>
                    <span v-else style="color:#67C23A;">打款成功</span>
                </template>
            </el-table-column>
            
            <el-table-column
                label="失败原因">
                <template slot-scope="scope">
                    <span v-if="scope.row.failMessage">{{scope.row.failMessage}}</span>
                    <span v-else>-</span>
                </template>
            </el-table-column>
        </el-table>

        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate, conversion } from '@/utils/utils'
export default {
    data () {
        return {
            tableData: [],
            pageNum: 1,
            pageSize: this._pageSize,
            total: 0,
            loading: false
        }
    },

    props: ['detail'],

    created () {
        if (this.detail && this.detail.userId) {
            this.getDetail()
        }
    },

    methods: {
        async getDetail () {
            if (this.loading) return
            this.loading = true
            let res = await this.$http.get('/user/getUserApply', {
                params: {
                    pageNum: this.pageNum,
                    pageSize: this.pageSize,
                    userId: this.detail.userId
                }
            })
            if (res.code === '0') {
                this.tableData = res.data
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.loading = false
        },

        initTime (time) {
            if (time) {
                return formatDate(new Date(time), 'YYYY-MM-DD HH:MM')
            } else {
                return '-'
            }
        },

        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getDetail()
        },

        pageChange (val) {
            this.pageNum = val
            this.getDetail()
        },

        // 数字转换
        conversion (val) {
            return conversion(val)
        }
    }
}
</script>

<style lang="scss" scoped>
    .money-box {
        .tools {
            margin-top: 10px;
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
